// 模拟数据
import listData from "./list.js";
import orderList from "./orderlist.js"

export function getOrderList(pageNum, pageSize, type) {
	return new Promise((resolute, reject) => {
		//延时一秒,模拟联

		setTimeout(() => {
			try {
				let list = [];
				let dat = [];
				if (type == 0) {//全部
					dat = orderList;
				} else {
					for (let i in orderList) {
						if (orderList[i].status == type) {
							dat.push(orderList[i]);
						}
					}
				}

				for (let i = (pageNum - 1) * pageSize; i < pageNum * pageSize; i++) {
					if (i === dat.length) break;

					list.push(dat[i])

				}

				list.sort(function() {
					return Math.random() - 0.5;
				})



				resolute(list);

			} catch (e) {
				//模拟接口请求失败
				reject(e);
			}

		}, 1000)


	})
}


export function getData(pageNum, pageSize) {
	return new Promise((resolute, reject) => {
		//延时一秒,模拟联

		setTimeout(() => {
			try {
				let list = [];
				let dat = listData;

				for (let i = (pageNum - 1) * pageSize; i < pageNum * pageSize; i++) {
					if (i === dat.length) break;

					list.push(dat[i])

				}

				list.sort(function() {
					return Math.random() - 0.5;
				})

				resolute(list);

			} catch (e) {
				//模拟接口请求失败
				reject(e);
			}

		}, 1000)


	})
}
export function getLaundryInfo(id) {
	return new Promise((resolute, reject) => {
		//延时一秒,模拟联


		try {

			let list = null;
			for (let i in listData) {
				if (id == listData[i].id) {
					list = listData[i];
					break;
				}
			}


			resolute(list);

		} catch (e) {
			//模拟接口请求失败
			reject(e);
		}




	})
}
